//作业 html元素只支持文本节点
//不需要打印层级结构,只分析文本和标签
//可选任务支持属性
//<div><span>123</span></div>
const EOF = Symbol('EOF')
function checkDec(str) {
  let state = start
  for(let s of str) {
    state = state(s)
  }
  state=  state(EOF)
  console.log(state)
  if(state === successed) {
    return true
  }else if(state === failed) {
    return false
  }
}

function start(c) {
  if(c==='0') {
    return receivedZero
  }else if(+c >= 1 && +c <= 9) { 
     return waitingForNumber
  }else if(c==='.') {
    return afterDot
  }
  else {
    return  failed
  }
}

function afterDot(c) {
  if(c===EOF) {
    return successed
  }
  else if(+c >=0 && +c <=9) {
    return  waitingForNumber
  }else {
    return failed
  }
}

function receivedZero(c) {
  if(c===EOF) {
    return successed
  }else {
    return failed
  }
}

function waitingForNumber(c) {
  if(c===EOF){
    return successed
  }else if(+c>= 0 && +c<= 9) {
    return  waitingForNumber
  }else if(c==='.') {
     return afterDot
  }
  else {
    return failed
  }
}


function successed() {
  throw Error('illegal call')
}

function failed() {
   return failed
}
console.log( checkDec('123') )
console.log( checkDec('123a') )
console.log( checkDec('1.2a') )
console.log( checkDec('1.') )
console.log( checkDec('.0e') )
console.log( checkDec('122..') )
